﻿using Mrc.Config;
using Mrc.RabbitMQ;
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.Extensions.DependencyInjection
{
    public static class MrcConfigOptionsExtensions
    {
        public static MrcConfigOptions UseRabbitMQ(this MrcConfigOptions options,ConfigFileInfo configFileInfo)
        {
            var kv = new KVConfigStoreCenter(new JsonConfigFileProvider(configFileInfo).GetAllStreams());

            options.RegisterExtension(new RabbitMQOptionsExtension(mqOptions => {
                mqOptions.HostName = kv.Get("ConfigRabbitMq:HostName");
                mqOptions.Port = Convert.ToInt32(kv.Get("ConfigRabbitMq:Port"));
                mqOptions.UserName = kv.Get("ConfigRabbitMq:UserName");
                mqOptions.Password = kv.Get("ConfigRabbitMq:Password");
                mqOptions.VirtualHost = kv.Get("ConfigRabbitMq:VirtualHost");
            }));            
            return options;
        }
    }
}
